using DG.Tweening;
using DG.Tweening.Core;
using Sirenix.OdinInspector;
using UnityEngine;

namespace WorkFlow.TweenGo
{

    public class CustomRotateTween : TweenGoBase<Transform,float>
    {
        public Vector3 startVector4;
        public Vector3 endVector4;

        [Range(0,1f)] 
#if UNITY_EDITOR
        [OnValueChanged("SetRotation")]
#endif
        public float currentValue = 0f;
        
        protected override Tweener CreateTween(DOGetter<float> startValueGetter, DOSetter<float> setter, float endValue, float duration)
        {
            return DOTween.To(startValueGetter, setter, endValue, duration);
        }

        protected override void SetValue(float value)
        {
            currentValue = value;
            SetRotation();
        }
        
        private void SetRotation()
        {
            var tempV4 = Vector4.Lerp(startVector4, endVector4, currentValue);
            Target.localEulerAngles = new Vector3(tempV4.x, tempV4.y, tempV4.z);
        }
    }
}
